* This script regresses structural estimates of the rate stability regulation cost on 
* RSR2000 implementation using DiD approach.

clear
macro drop _all 
set more off
pause on
cls

global wsize = 2

*******************
* load cost estimates and data
*******************
* exported in supply_estimation/export_cost_estimates.m.
* the data are at the market level.
import delimited "cost_estimates_market_level.csv", clear
rename v1 fc
rename v2 vc_sw
rename v3 vc_ew
rename v4 state_id
rename v5 year
rename v6 reg_year
rename v7 in_regression 
rename v8 c1_sw
rename v9 c1_ew

*******************
* create vars
*******************
* treatment for DiD dummy
* note: PostReg=0 for never treated states as reg_year=3000 for them
gen PostReg1 = (year>=reg_year)
gen PostReg2 = (year+1>=reg_year)
gen PostReg3 = (year+2>=reg_year)

* treatment dummy for event study
gen year_post_reg = year - reg_year if reg_year ~= 3000
replace year_post_reg = . if inrange(year_post_reg, -$wsize, $wsize) ==0
replace year_post_reg = year_post_reg + $wsize 

* summarize
sum 

*******************
* label
*******************
label var fc "Rate adjustment cost - fixed cost"
label var vc_sw "Rate adjustment cost - variable cost (share weighted)"
label var vc_ew "Rate adjustment cost - variable cost (equal weights)"
label var c1_sw "Initial rate reg cost (share weighted)"
label var c1_ew "Initial rate reg cost (equal weights)"

*******************
* regressions
*******************
global DepVars "fc vc_sw c1_sw"

foreach depvar of varlist $DepVars {
	reghdfe `depvar' PostReg2 i.year if reg_year<3000, a(state_id) cluster(state_id)
	sum `depvar' if e(sample)
}






